const http = require('http')
const url = require('url')

const server = http.createServer((req, res) => {
  var urlString = req.url
  var urlObj = url.parse(urlString, true)
  switch (urlObj.pathname) {
    case '/api':
      res.writeHead(200, {
        "Content-Type": "application/json",
        "Access-Control-Allow-Origin": "*"
      })
      res.write(JSON.stringify({ name: 'mal', age: 18 }))
      break
    default:
      res.write('not found page')
      break
  }
  res.end()
})

server.listen(5000, () => {
  console.log('6000端口的服务已开启');
})
